<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">

    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>${sysconf.proname}</title>
    <link rel="shortcut icon" type="image/x-icon"/>
    <link rel="stylesheet" href="static/css/font.css">
    <link rel="stylesheet" href="static/css/xadmin.css">
    <script type="text/javascript" src="static/lib/jquery/jquery.min.js"></script>
    <script charset="utf-8" src="static/lib/layui/layui.js"></script>
    <script type="text/javascript"  src="static/js/xadmin.js"></script>
    <link rel="stylesheet" href="static/css/style.css">

</head>
<body>

<div class="login-main">
    <header class="layui-elip">登录</header>
    <form class="layui-form">
        <div class="layui-input-inline">
            <input type="text" name="account" lay-verify="required"  placeholder="账号" autocomplete="off"
                   class="layui-input">
        </div>
        <c:choose>
            <c:when test="${sysconf.logintype eq 'pass'}">
                <div class="layui-input-inline">
                    <input type="password" name="password" lay-verify="required" lay-vertype="tips" placeholder="密码" autocomplete="off"
                           class="layui-input">
                </div>
            </c:when>
            <c:otherwise>
                <div class="layui-input-inline" >
                    <input name="yzm" lay-verify="required" placeholder="验证码" style="width:65%;" type="text"  autocomplete="off"  class="layui-input-inline layui-input" >
                    <a class="layui-btn layui-btn-primary yzm" onclick="time(this)" style="width: 100px;margin-top: -15px;">点击获取</a>
                </div>
            </c:otherwise>

        </c:choose>

        <div class="layui-input-inline login-btn">
            <button lay-submit lay-filter="login" class="layui-btn layui-btn-blue">登录</button>
        </div>
        
        <!--<div class="layui-input-inline">-->
            <!--<button type="button" class="layui-btn layui-btn-primary">QQ登录</button>-->
        <!--</div>-->
        <!--<div class="layui-input-inline">-->
            <!--<button type="button" class="layui-btn layui-btn-normal">微信登录</button>-->
        <!--</div>-->
        <!-- <p><a href="static/register" class="fl">立即注册</a><a href="javascript:" class="fr">忘记密码？</a></p> -->
    </form>
</div>

<script type="text/javascript">
	//获取验证码
		var wait=60; 
		function time(o) { 
	        if (wait <= 0) { 
	            //o.removeAttribute("disabled");
	            $(o).attr("onclick","time(this)");
	            $(o).removeClass("layui-btn-disabled")
	            
	            /* o.style.color="#fff"; */
	            o.innerText="点击获取"; 
	            wait = 60; 
	        } else { 
	        	if(wait==60){
		        	getsmsYzm();
		        }
		        $(o).attr("onclick","");
	        	$(o).addClass("layui-btn-disabled")
	            
	            /* o.style.color="#000"; */
	            o.innerText=wait+"s"; 
	            wait--; 
	            setTimeout(function() { 
	                time(o) 
	            }, 
	            1000) 
	        } 
	    } 
	    
	    function getsmsYzm(){
		    
        	var account = $("input[name=account]").val();
        	if(account!=null&&account!=""){
        		$.post("user/getsmsYzm",{"account":account},function(data){ 
					if(data.res==1){
						layer.msg("验证码发送成功");
					}else{
						layer.msg(data.msg);
						wait = 0;
					}
				},"JSON");
	        	
        	}else{
        		layer.msg("请输入登录账号");
        		wait=0;
        	} 
        
        }
	    
	    


    // 如果在 iframe 中, 则跳出 iframe
    if (self !== top) {
        top.location.href = location.href;
    }
    $(function () {
        layui.use(['form', 'layer', 'jquery'], function () {

            // 操作对象
            var form = layui.form;
            var $ = layui.jquery;
            form.on('submit(login)', function (data) {
                $.post('user/login', data.field, function (data) {
                    if(data.res==1){
						window.location.href='${pageContext.request.contextPath }/main';
					}else{			
						layer.msg(data.msg);
					}
                });
                return false;
            });
        });
    });


    function generateCaptcha(obj) {
        $(obj).attr("src", "/captcha?timestamp=" + (new Date()).valueOf());
    }

    function loginDone(data) {
        layer.msg("登陆成功, 即将跳转到首页!", {
            icon: 1,
            time: 1000
        }, function () {
            location.href = 'main';
        });
    }

</script>
</body>
</html>